<?php
/*******************************************************************************
 *
 *  filename    : PersonEditor.php
 *  last change : 2003-01-04
 *  website     : http://www.infocentral.org
 *  copyright   : Copyright 2001, 2002, 2003 Deane Barker, Chris Gebhardt
 *
 *  InfoCentral is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 ******************************************************************************/

//Include the function library
require "Include/Config.php";
require "Include/Functions.php";

//Set the page title
$sPageTitle = gettext("Family Editor");

//Get the FamilyID from the querystring
$iFamilyID = FilterInput($_GET["FamilyID"],'int');

// Security: User must have Add or Edit Records permission to use this form in those manners
// Clean error handling: (such as somebody typing an incorrect URL ?PersonID= manually)
if (strlen($iFamilyID) > 0)
{
	if (!$_SESSION['bEditRecords'])
	{
		Redirect("Menu.php");
		exit;
	}

	$sSQL = "SELECT fam_ID FROM family_fam WHERE fam_ID = " . $iFamilyID;
	if (mysql_num_rows(RunQuery($sSQL)) == 0)
	{
		Redirect("Menu.php");
		exit;
	}
}
elseif (!$_SESSION['bAddRecords'])
{
		Redirect("Menu.php");
		exit;
}


//Is this the second pass?
if (isset($_POST["FamilySubmit"]) || isset($_POST["FamilySubmitAndAdd"]))
{
	//Assign everything locally
	$sNoIndFam = FilterInput($_POST["NoIndFam"]);
	$sName = FilterInput($_POST["Name"]);
	$sAddress1 = FilterInput($_POST["Address1"]);
//Add for GPIB
	$sKompleks1 = FilterInput($_POST["Kompleks1"]);
	$sRTRW1 = FilterInput($_POST["RTRW1"]);
	$sKelurahan1 = FilterInput($_POST["Kelurahan1"]);
//End Add
	$sAddress2 = FilterInput($_POST["Address2"]);
//Add for GPIB
	$sKompleks2 = FilterInput($_POST["Kompleks2"]);
	$sRTRW2 = FilterInput($_POST["RTRW2"]);
	$sKelurahan2 = FilterInput($_POST["Kelurahan2"]);
//End Add
	$sCity = FilterInput($_POST["City"]);
	$sZip = FilterInput($_POST["Zip"]);
	$sCountry = FilterInput($_POST["Country"]);
	$iFamilyMemberRows = FilterInput($_POST["FamCount"]);

	if ($sCountry == "United States" || $sCountry == "Canada")
		$sState = FilterInput($_POST["State"]);
	else
		$sState = FilterInput($_POST["StateTextbox"]);

	$sHomePhone = FilterInput($_POST["HomePhone"]);
	$sWorkPhone = FilterInput($_POST["WorkPhone"]);
	$sCellPhone = FilterInput($_POST["CellPhone"]);
	$sEmail = FilterInput($_POST["Email"]);
	$dWeddingDate = FilterInput($_POST["WeddingDate"]);
// Added for GPIB
	$dMembershipDate = FilterInput($_POST["MembershipDate"]);
	$aAsalGS = FilterInput($_POST["AsalGS"]);
	$sNamaGS = FilterInput($_POST["NamaGS"]);
	$sNamaSek = FilterInput($_POST["NamaSek"]);
	$sStatusRumah = FilterInput($_POST["StatusRumah"]);
// End Added
	$bNoFormat_HomePhone = isset($_POST["NoFormat_HomePhone"]);
	$bNoFormat_WorkPhone = isset($_POST["NoFormat_WorkPhone"]);
	$bNoFormat_CellPhone = isset($_POST["NoFormat_CellPhone"]);

	//Loop through the Family Member 'quick entry' form fields
	for ($iCount = 1; $iCount <= $iFamilyMemberRows; $iCount++)
	{
		// Assign everything to arrays
		$aFirstNames[$iCount] = FilterInput($_POST["FirstName" . $iCount]);
		$aMiddleNames[$iCount] = FilterInput($_POST["MiddleName" . $iCount]);
		$aLastNames[$iCount] = FilterInput($_POST["LastName" . $iCount]);
		$aRoles[$iCount] = FilterInput($_POST["Role" . $iCount],'int');
		$aGenders[$iCount] = FilterInput($_POST["Gender" . $iCount],'int');
		$aBirthDays[$iCount] = FilterInput($_POST["BirthDay" . $iCount],'int');
		$aBirthMonths[$iCount] = FilterInput($_POST["BirthMonth" . $iCount],'int');
		$aBirthYears[$iCount] = FilterInput($_POST["BirthYear" . $iCount],'int');
		$aClassification[$iCount] = FilterInput($_POST["Classification" . $iCount],'int');
		$aPersonIDs[$iCount] = FilterInput($_POST["PersonID" . $iCount],'int');

		// Make sure first names were entered if editing existing family
		if (strlen($iFamilyID) > 0)
		{
			if (strlen($aFirstNames[$iCount]) == 0)
			{
				$aFirstNameError[$iCount] = gettext("First name must be entered");
				$bErrorFlag = True;
			}
		}

		// Validate any family member birthdays
		if (strlen($aFirstNames[$iCount]) > 0 && strlen($aBirthYears[$iCount]) > 0)
		{
			if ($aBirthYears[$iCount] > 2155 || $aBirthYears[$iCount] < 1901)
			{
				$aBirthDateError[$iCount] = gettext("Invalid Year: allowable values are 1901 to 2155");
				$bErrorFlag = True;
			}
			elseif ($aBirthMonths[$iCount] > 0 && $aBirthDays[$iCount] > 0)
			{
				if (!checkdate($aBirthMonths[$iCount],$aBirthDays[$iCount],$aBirthYears[$iCount]))
				{
					$aBirthDateError[$iCount] = gettext("Invalid Birth Date.");
					$bErrorFlag = True;
				}
			}
		}

	}

	//Did they enter a name?
	if (strlen($sName) < 1)
	{
		$sNameError = gettext("Mohon memasukan sebuah Nama.");
		$bErrorFlag = True;

	}

	//Validate Wedding Date if one was entered
	// Currently, format is a string: YYYY-MM-DD
	if (strlen($dWeddingDate) > 0)
	{
		list($iYear, $iMonth, $iDay) = sscanf($dWeddingDate,"%04d-%02d-%02d");

		if ( !checkdate($iMonth,$iDay,$iYear) )
		{
			$sWeddingDateError = "<span style=\"color: red; \"> " . gettext("Not a valid WeddingDate") . "</span>";
			$bErrorFlag = true;
		}
	}

// Added for GPIB
	// Validate Membership Date if one was entered
	if (strlen($dMembershipDate) > 0)
	{
		list($iYear, $iMonth, $iDay) = sscanf($dMembershipDate,"%04d-%02d-%02d");
		if ( !checkdate($iMonth,$iDay,$iYear) )
		{
			$sMembershipDateError = "<span style=\"color: red; \">" . gettext("Not a valid Membership Date") . "</span>";
			$bErrorFlag = true;
		}
	}
// Added for GPIB

	//If no errors, then let's update...
	if (!$bErrorFlag)
	{
		// Format the phone numbers before we store them
		if (!$bNoFormat_HomePhone) $sHomePhone = CollapsePhoneNumber($sHomePhone,$sCountry);
		if (!$bNoFormat_WorkPhone) $sWorkPhone = CollapsePhoneNumber($sWorkPhone,$sCountry);
		if (!$bNoFormat_CellPhone) $sCellPhone = CollapsePhoneNumber($sCellPhone,$sCountry);

		if ( strlen($dWeddingDate) > 0 )
			$dWeddingDate = "\"" . $dWeddingDate . "\"";
		else
			$dWeddingDate = "NULL";

// Added for GPIB
		if ( strlen($dMembershipDate) > 0 )
			$dMembershipDate = "\"" . $dMembershipDate . "\"";
		else
			$dMembershipDate = "NULL";

// End Added

		//Write the base SQL depending on the Action
		if (strlen($iFamilyID) < 1)
		{
// Edited for GPIB
//			$sSQL = "INSERT INTO family_fam (fam_Name, fam_Address1, fam_Address2, fam_City, fam_State, fam_Zip, fam_Country, fam_HomePhone, fam_WorkPhone, fam_CellPhone, fam_Email, fam_WeddingDate, fam_DateEntered, fam_EnteredBy) VALUES ('" . $sName . "','" . $sAddress1 . "','" . $sAddress2 . "','" . $sCity . "','" . $sState . "','" . $sZip . "','" . $sCountry . "','" . $sHomePhone . "','" . $sWorkPhone . "','" . $sCellPhone . "','" . $sEmail . "'," . $dWeddingDate . ",'" . date("YmdHis") . "'," . $_SESSION['iUserID'] . ")";
			$sSQL = "INSERT INTO family_fam (fam_NoIndFam, fam_Name, fam_Address1, fam_Kompleks1, fam_RTRW1, fam_Kelurahan1, fam_Address2, fam_Kompleks2, fam_RTRW2, fam_Kelurahan2, fam_City, fam_State, fam_Zip, fam_Country, fam_HomePhone, fam_WorkPhone, fam_CellPhone, fam_Email, fam_WeddingDate, fam_MembershipDate, fam_AsalGS, fam_NamaGS, fam_NamaSek, fam_StatusRumah, fam_DateEntered, fam_EnteredBy) VALUES ('" . $sNoIndFam . "', '" . $sName . "','" . $sAddress1 . "','" . $sKompleks1 . "','" . $sRTRW1 . "','" . $sKelurahan1 . "','" . $sAddress2 . "','" . $sKompleks2 . "','" . $sRTRW2 . "','" . $sKelurahan2 . "','" . $sCity . "','" . $sState . "','" . $sZip . "','" . $sCountry . "','" . $sHomePhone . "','" . $sWorkPhone . "','" . $sCellPhone . "','" . $sEmail . "'," . $dWeddingDate . "," . $dMembershipDate . ",'" . $aAsalGS . "','" . $sNamaGS . "','" .$sNamaSek. "','".$sStatusRumah."','" . date("YmdHis") . "'," . $_SESSION['iUserID'] . ")";

			$bGetKeyBack = true;
		}
		else
		{
// Edited for GPIB
//			$sSQL = "UPDATE family_fam SET fam_Name='" . $sName . "', fam_Address1='" . $sAddress1 . "', fam_Address2='" . $sAddress2 . "', fam_City='" . $sCity . "', fam_State='" . $sState . "', fam_Zip='" . $sZip . "', fam_Country='" . $sCountry . "', fam_HomePhone='" . $sHomePhone . "', fam_WorkPhone='" . $sWorkPhone . "', fam_CellPhone='" . $sCellPhone . "', fam_Email='" . $sEmail . "', fam_WeddingDate=" . $dWeddingDate . ", fam_DateLastEdited='" . date("YmdHis") . "', fam_EditedBy = " . $_SESSION['iUserID'] . " WHERE fam_ID = " . $iFamilyID;
			$sSQL = "UPDATE family_fam SET fam_NoIndFam='" . $sNoIndFam . "',fam_Name='" . $sName . "', fam_Address1='" . $sAddress1 . "', fam_Kompleks1='" . $sKompleks1 . "', fam_RTRW1='" . $sRTRW1 . "', fam_Kelurahan1='" . $sKelurahan1 . "', fam_Address2='" . $sAddress2 . "', fam_Kompleks2='" . $sKompleks2 . "', fam_RTRW2='" . $sRTRW2 . "', fam_Kelurahan2='" . $sKelurahan2 . "', fam_City='" . $sCity . "', fam_State='" . $sState . "', fam_Zip='" . $sZip . "', fam_Country='" . $sCountry . "', fam_HomePhone='" . $sHomePhone . "', fam_WorkPhone='" . $sWorkPhone . "', fam_CellPhone='" . $sCellPhone . "', fam_Email='" . $sEmail . "', fam_WeddingDate=" . $dWeddingDate . ", fam_MembershipDate=" . $dMembershipDate . ", fam_AsalGS='" . $aAsalGS . "', fam_NamaGS='" . $sNamaGS . "', fam_NamaSek='" . $sNamaSek . "', fam_StatusRumah='" . $sStatusRumah . "', fam_DateLastEdited='" . date("YmdHis") . "', fam_EditedBy = " . $_SESSION['iUserID'] . " WHERE fam_ID = " . $iFamilyID;

			$bGetKeyBack = false;
		}

		//Execute the SQL
		RunQuery($sSQL);

		//If the user added a new record, we need to key back to the route to the FamilyView page
		if ($bGetKeyBack)
		{
			//Get the key back
			$sSQL = "SELECT MAX(fam_ID) AS iFamilyID FROM family_fam";
			$rsLastEntry = RunQuery($sSQL);
			extract(mysql_fetch_array($rsLastEntry));

			//Run through the family member arrays...
			for ($iCount = 1; $iCount <= $iFamilyMemberRows; $iCount++)
			{
				if (strlen($aFirstNames[$iCount]) > 0)
				{
					if (strlen($aBirthYears[$iCount]) < 4)
					{
						$aBirthYears[$iCount] = "NULL";
					}

					//If no last name is entered for a member, use the family name.
					if(strlen($aLastNames[$iCount]) && $aLastNames[$iCount] != $sName)
					{
						$sLastNameToEnter = $aLastNames[$iCount];
					}
					else
					{
						$sLastNameToEnter = $sName;
					}

					RunQuery("LOCK TABLES person_per WRITE, person_custom WRITE");
					$sSQL = "INSERT INTO person_per (per_FirstName, per_MiddleName, per_LastName, per_fam_ID, per_fmr_ID, per_DateEntered, per_EnteredBy, per_Gender, per_BirthDay, per_BirthMonth, per_BirthYear, per_cls_ID) VALUES ('$aFirstNames[$iCount]','$aMiddleNames[$iCount]','$sLastNameToEnter',$iFamilyID,$aRoles[$iCount],'" . date("YmdHis") . "'," . $_SESSION['iUserID'] . ",$aGenders[$iCount],$aBirthDays[$iCount],$aBirthMonths[$iCount],$aBirthYears[$iCount],$aClassification[$iCount])";
					RunQuery($sSQL);
					$sSQL = "INSERT INTO person_custom (per_ID) VALUES (" . mysql_insert_id() . ")";
					RunQuery($sSQL);
					RunQuery("UNLOCK TABLES");
				}
			}
		} else {
			for ($iCount = 1; $iCount <= $iFamilyMemberRows; $iCount++)
			{
				if (strlen($aFirstNames[$iCount]) > 0)
				{
					if (strlen($aBirthYears[$iCount]) < 4)
					{
						$aBirthYears[$iCount] = "NULL";
					}

					//If no last name is entered for a member, use the family name.
					if(strlen($aLastNames[$iCount]) && $aLastNames[$iCount] != $sName)
					{
						$sLastNameToEnter = $aLastNames[$iCount];
					}
					else
					{
						$sLastNameToEnter = $sName;
					}
					RunQuery("LOCK TABLES person_per WRITE, person_custom WRITE");
					$sSQL = "UPDATE person_per SET per_FirstName='" . $aFirstNames[$iCount] . "', per_MiddleName='" . $aMiddleNames[$iCount] . "',per_LastName='" . $aLastNames[$iCount] . "',per_Gender='" . $aGenders[$iCount] . "',per_fmr_ID='" . $aRoles[$iCount] . "',per_BirthMonth='" . $aBirthMonths[$iCount] . "',per_BirthDay='" . $aBirthDays[$iCount] . "',per_BirthYear='" . $aBirthYears[$iCount] . "',per_cls_ID='" . $aClassification[$iCount] . "' WHERE per_ID=" . $aPersonIDs[$iCount];
					RunQuery($sSQL);
					RunQuery("UNLOCK TABLES");
				}
			}
		}

		//Which submit button did they press?
		if (isset($_POST["FamilySubmit"]))
		{
			//Send to the view of this person
			Redirect("FamilyView.php?FamilyID=" . $iFamilyID);
		} else {
			//Reload to editor to add another record
			Redirect("FamilyEditor.php");
		}
	}
}
else
{
	//FirstPass
	//Are we editing or adding?
	if (strlen($iFamilyID) > 0)
	{
		//Editing....
		//Get the information on this family
		$sSQL = "SELECT * FROM family_fam WHERE fam_ID = " . $iFamilyID;
		$rsFamily = RunQuery($sSQL);
		extract(mysql_fetch_array($rsFamily));

		$iFamilyID = $fam_ID;
		$sNoIndFam = $fam_NoIndFam;
		$sName = $fam_Name;
		$sAddress1 = $fam_Address1;
// Added for GPIB
		$sKompleks1 = $fam_Kompleks1;
		$sRTRW1 = $fam_RTRW1;
		$sKelurahan1 = $fam_Kelurahan1;
// End Add
		$sAddress2 = $fam_Address2;
// Added for GPIB
		$sKompleks2 = $fam_Kompleks2;
		$sRTRW2 = $fam_RTRW2;
		$sKelurahan2 = $fam_Kelurahan2;
// End Add
		$sCity = $fam_City;
		$sState = $fam_State;
		$sZip	= $fam_Zip;
		$sCountry = $fam_Country;
		$sHomePhone = $fam_HomePhone;
		$sWorkPhone = $fam_WorkPhone;
		$sCellPhone = $fam_CellPhone;
		$sEmail = $fam_Email;
		$dWeddingDate = $fam_WeddingDate;
// Added for GPIB
		$dMembershipDate = $fam_MembershipDate;
		$aAsalGS = $fam_AsalGS;
		$sNamaGS = $fam_NamaGS;
		$sNamaSek = $fam_NamaSek;
		$sStatusRumah = $fam_StatusRumah;
// End Add

		// Expand the phone number
		$sHomePhone = ExpandPhoneNumber($sHomePhone,$sCountry,$bNoFormat_HomePhone);
		$sWorkPhone = ExpandPhoneNumber($sWorkPhone,$sCountry,$bNoFormat_WorkPhone);
		$sCellPhone = ExpandPhoneNumber($sCellPhone,$sCountry,$bNoFormat_CellPhone);

		$sSQL = "SELECT * FROM person_per LEFT JOIN family_fam ON per_fam_ID = fam_ID WHERE per_fam_ID =" . $iFamilyID . " ORDER BY per_fmr_ID";
		$rsMembers = RunQuery($sSQL);
		$iCount = 0;
		$iFamilyMemberRows = 0;
		while ($aRow = mysql_fetch_array($rsMembers))
		{
			extract($aRow);
			$iCount++;
			$iFamilyMemberRows++;
			$aFirstNames[$iCount] = $per_FirstName;
			$aMiddleNames[$iCount] = $per_MiddleName;
			$aLastNames[$iCount] = $per_LastName;
			$aGenders[$iCount] = $per_Gender;
			$aRoles[$iCount] = $per_fmr_ID;
			$aBirthMonths[$iCount] = $per_BirthMonth;
			$aBirthDays[$iCount] = $per_BirthDay;
			if ($per_BirthYear > 0)
				$aBirthYears[$iCount] = $per_BirthYear;
			else
				$aBirthYears[$iCount] = "";
			$aClassification[$iCount] = $per_cls_ID;
			$aPersonIDs[$iCount] = $per_ID;
		}
	}
	else
	{
		//Adding....
		//Set defaults
		$sCity = $sDefaultCity;
		$sCountry = $sDefaultCountry;
		$sState = $sDefaultState;
		$iClassification = "0";
		$iFamilyMemberRows = 15;
	}
}

?>

<? require "Include/Header.php"; ?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'] . "?FamilyID=" . $iFamilyID ?>">
<input type="hidden" Name="sAction" value="<?php echo $sAction; ?>">
<input type="hidden" Name="iFamilyID" value="<?php echo $iFamilyID; ?>">
<input type="hidden" name="FamCount" value="<?php echo $iFamilyMemberRows; ?>">

<table cellpadding="3" align="center">

	<tr>
		<td colspan="2" align="center">
			<input type="submit" class="icButton" <?php echo 'value="' . gettext("Simpan") . '"'; ?> Name="FamilySubmit">
			<?php if ($_SESSION['bAddRecords']) { echo "<input type=\"submit\" class=\"icButton\" value=\"" . gettext("Simpan dan Tambah") . "\" name=\"FamilySubmitAndAdd\">"; }
			echo "<input type=\"button\" class=\"icButton\" value=\"" . gettext("Batal") . "\"Name=\"FamilyCancel\"";
			if (strlen($iFamilyID) > 0)
				echo "\"onclick=\"javascript:document.location='FamilyView.php?FamilyID=$iFamilyID';\">";
			else
				echo "\"onclick=\"javascript:document.location='SelectList.php';\">";
			if ( $bErrorFlag ) echo "<br><br><span class=\"LargeText\" style=\"color: red;\">Invalid fields or selections. Changes not saved! Please correct and try again!</span><br><br>"; ?>
		</td>
	</tr>

	<tr>
		<td class="LabelColumn"><?php echo gettext("No Induk Keluarga:"); ?></td>
		<td class="TextColumnWithBottomBorder"><input type="text" Name="NoIndFam" id="NoIndFam" value="<?php echo htmlentities(stripslashes($sNoIndFam)); ?>" maxlength="48"><font color="red"><?php echo $sNameError; ?></font></td>
	</tr>
	<tr>
		<td class="LabelColumn"><?php echo gettext("Nama Sektor Pelayan:"); ?></td>
		<td class="TextColumnWithBottomBorder"><input type="text" Name="NamaSek" value="<?php echo htmlentities(stripslashes($sNamaSek)); ?>" size="30" maxlength="50"></td>
	</tr>

	<tr>
		<td>&nbsp;</td>
	</tr>

	<tr>
		<td class="LabelColumn"><?php echo gettext("Nama Keluarga:"); ?></td>
		<td class="TextColumnWithBottomBorder"><input type="text" Name="Name" id="FamilyName" value="<?php echo htmlentities(stripslashes($sName)); ?>" maxlength="48"><font color="red"><?php echo $sNameError; ?></font></td>
	</tr>

	<tr>
		<td>&nbsp;</td>
	</tr>

	<tr>
		<td class="LabelColumn"><?php echo gettext("Alamat Jalan / Domisili:"); ?></td>
		<td class="TextColumn"><input type="text" Name="Address1" value="<?php echo htmlentities(stripslashes($sAddress1)); ?>" size="50" maxlength="250"></td>
	</tr>
	<tr>
		<td class="LabelColumn"><?php echo gettext("Pemukiman / Kompleks:"); ?></td>
		<td class="TextColumn"><input type="text" Name="Kompleks1" value="<?php echo htmlentities(stripslashes($sKompleks1)); ?>" size="50" maxlength="250"></td>
	</tr>
	<tr>
		<td class="LabelColumn"><?php echo gettext("RT / RW:"); ?></td>
		<td class="TextColumn"><input type="text" Name="RTRW1" value="<?php echo htmlentities(stripslashes($sRTRW1)); ?>" size="50" maxlength="250"></td>
	</tr>
	<tr>
		<td class="LabelColumn"><?php echo gettext("Kelurahan:"); ?></td>
		<td class="TextColumn"><input type="text" Name="Kelurahan1" value="<?php echo htmlentities(stripslashes($sKelurahan1)); ?>" size="50" maxlength="250"></td>
	</tr>

<!--
	<tr>
		<td class="LabelColumn"><?php echo gettext("Address2:"); ?></td>
		<td class="TextColumn"><input type="text" Name="Address2" value="<?php echo htmlentities(stripslashes($sAddress2)); ?>" size="50" maxlength="250"></td>
	</tr>
	<tr>
		<td class="LabelColumn"><?php echo gettext("Kompleks2:"); ?></td>
		<td class="TextColumn"><input type="text" Name="Kompleks2" value="<?php echo htmlentities(stripslashes($sKompleks2)); ?>" size="50" maxlength="250"></td>
	</tr>
	<tr>
		<td class="LabelColumn"><?php echo gettext("RT-RW2:"); ?></td>
		<td class="TextColumn"><input type="text" Name="RTRW2" value="<?php echo htmlentities(stripslashes($sRTRW2)); ?>" size="50" maxlength="250"></td>
	</tr>
	<tr>
		<td class="LabelColumn"><?php echo gettext("Kelurahan2:"); ?></td>
		<td class="TextColumn"><input type="text" Name="Kelurahan2" value="<?php echo htmlentities(stripslashes($sKelurahan2)); ?>" size="50" maxlength="250"></td>
	</tr>
-->
	<tr>
		<td class="LabelColumn"><?php echo gettext("Kecamatan :"); ?></td>
		<td class="TextColumn"><input type="text" Name="City" value="<?php echo htmlentities(stripslashes($sCity)); ?>" maxlength="50"></td>
	</tr>

	<tr>
		<td class="LabelColumn"><?php echo gettext("Propinsi:"); ?></td>
		<td class="TextColumn">
			<input type="text" name="StateTextbox" value="<?php if ($sCountry != "United States" && $sCountry != "Canada") echo htmlentities(stripslashes($sState)); ?>" size="20" maxlength="30">
		</td>
	</tr>

	<tr>
		<td class="LabelColumn">
			<?php
			  echo gettext("Kode Pos:");
			?>
		</td>
		<td class="TextColumn">
			<input type="text" Name="Zip" value="<?php echo htmlentities(stripslashes($sZip)); ?>" maxlength="10" size="8">
		</td>

	</tr>

	<tr>
		<td class="LabelColumn"><?php echo gettext("Negara:"); ?></td>
		<td class="TextColumnWithBottomBorder">
			<?php require "Include/CountryDropDown.php" ?>
		</td>
	</tr>

	<tr>
		<td>&nbsp;</td>
	</tr>

	<tr>
		<td class="LabelColumn"><?php echo gettext("Telfon Rumah:"); ?></td>
		<td class="TextColumn">
			<input type="text" Name="HomePhone" value="<?php echo htmlentities(stripslashes($sHomePhone)); ?>" size="30" maxlength="30">
			<input type="checkbox" name="NoFormat_HomePhone" value="1" <?php if ($bNoFormat_HomePhone) echo " checked";?>><?php echo gettext("Jangan diatur otomatis"); ?>
		</td>
	</tr>

	<tr>
		<td class="LabelColumn"><?php echo gettext("Telfon Kantor:"); ?></td>
		<td class="TextColumn">
			<input type="text" name="WorkPhone" value="<?php echo htmlentities(stripslashes($sWorkPhone)); ?>" size="30" maxlength="30">
			<input type="checkbox" name="NoFormat_WorkPhone" value="1" <?php if ($bNoFormat_WorkPhone) echo " checked";?>><?php echo gettext("Jangan diatur otomatis"); ?>
		</td>
	</tr>

	<tr>
		<td class="LabelColumn"><?php echo gettext("Handphone:"); ?></td>
		<td class="TextColumn">
			<input type="text" name="CellPhone" value="<?php echo htmlentities(stripslashes($sCellPhone)); ?>" size="30" maxlength="30">
			<input type="checkbox" name="NoFormat_CellPhone" value="1" <?php if ($bNoFormat_CellPhone) echo " checked";?>><?php echo gettext("Jangan diatur otomatis"); ?>
		</td>
	</tr>

	<tr>
		<td class="LabelColumn"><?php echo gettext("Email:"); ?></td>
		<td class="TextColumnWithBottomBorder"><input type="text" Name="Email" value="<?php echo htmlentities(stripslashes($sEmail)); ?>" size="30" maxlength="50"></td>
	</tr>

	<tr>
		<td>&nbsp;</td>
	</tr>

	<tr>
		<td class="LabelColumn"><?php echo gettext("Tanggal Pernikahan:"); ?></td>
		<td class="TextColumnWithBottomBorder"><input type="text" Name="WeddingDate" value="<?php echo $dWeddingDate; ?>" maxlength="10" id="sel1" size="15">&nbsp;<input type="image" onclick="return showCalendar('sel1', 'y-mm-dd');" src="Images/calendar.gif">&nbsp;<span class="SmallText"><?php echo gettext("[format: YYYY-MM-DD]"); ?></span><font color="red"><?php echo "<BR>" . $sWeddingDateError ?></font></td>
	</tr>
<?php
// Added for GPIB ?>
	<tr> <td>&nbsp;</td> </tr>
	<tr>
		<td class="LabelColumn" <?php addToolTip("Format: YYYY-MM-DD<br>or enter the date by clicking on the calendar icon to the right."); ?>><?php echo gettext("Tanggal Terdaftar:"); ?></td>
		<td class="TextColumn"><input type="text" name="MembershipDate" value="<?php echo $dMembershipDate; ?>" maxlength="10" id="sel2" size="15">&nbsp;<input type="image" onclick="return showCalendar('sel2', 'y-mm-dd');" src="Images/calendar.gif"> <span class="SmallText"><?php echo gettext("[format: YYYY-MM-DD]"); ?></span><font color="red"><?php echo $sMembershipDateError ?></font></td>
	</tr>

	<tr>
		<td class="LabelColumn"><?php echo gettext("Asal Gereja Sebelum:"); ?></td>
		<td class="TextColumnWithBottomBorder">
			<select name="AsalGS">
				<option value="G" <?php if ($aAsalGS == "G") echo "selected" ?> ><?php echo gettext("GPIB"); ?></option>
				<option value="N" <?php if ($aAsalGS == "N") echo "selected" ?> ><?php echo gettext("Non-GPIB"); ?></option>
			</select></td>
	</tr>

	<tr>
		<td class="LabelColumn"><?php echo gettext("Nama Gereja Sebelum:"); ?></td>
		<td class="TextColumnWithBottomBorder"><input type="text" Name="NamaGS" value="<?php echo htmlentities(stripslashes($sNamaGS)); ?>" size="30" maxlength="50"></td>
	</tr>

	<tr>
		<td class="LabelColumn"><?php echo gettext("Status tempat tinggal :"); ?></td>
		<td class="TextColumnWithBottomBorder">
		<select name="StatusRumah">
		    <option value="Sendiri" <?php if ($aAsalGS == "Sendiri") echo "selected" ?> ><?php echo gettext("Sendiri"); ?></option>
		    <option value="Dinas" <?php if ($aAsalGS == "Dinas") echo "selected" ?> ><?php echo gettext("Dinas"); ?></option>
			<option value="Sewa" <?php if ($aAsalGS == "Sewa") echo "selected" ?> ><?php echo gettext("Sewa"); ?></option>
			<option value="Keluarga" <?php if ($aAsalGS == "Keluarga") echo "selected" ?> ><?php echo gettext("Keluarga"); ?></option>
		</select></td>
	</tr>

<?php
// End Added ?>
	<tr>
		<td>&nbsp;</td>
	</tr>

	<?php if ($iFamilyMemberRows > 0) { ?>

	<tr>
		<td colspan="2">
		<div class="MediumText"><center><?php if (!strlen($iFamilyID)) { echo gettext("Anda dapat membuat Anggota Keluarga sekarang atau menambahkannya nanti.  Semua entries akan menjadi record warga jemaat <i>baru</i>."); }?></center></div><br><br>
		<table cellpadding="3" cellspacing="0" width="100%">
		<tr align="center">
			<td>&nbsp;</td>
			<td colspan="3"><i><b><?php echo gettext("Nama Lengkap"); ?></b></i></td>
			<td colspan="2">&nbsp;</td>
			<td colspan="3"><i><b><?php echo gettext("Tanggal Lahir"); ?></b></i></td>
		</tr>
		<tr class="TableHeader" align="center">
			<td><?php echo gettext("Anggota Keluarga"); ?></td>
			<td><?php echo gettext("Depan"); ?></td>
			<td><?php echo gettext("Tengah"); ?></td>
			<td><?php echo gettext("Belakang"); ?></td>
			<td><?php echo gettext("Jenis Kelamin"); ?></td>
			<td><?php echo gettext("Hubungan Keluarga"); ?></td>
			<td><?php echo gettext("Bulan"); ?></td>
			<td><?php echo gettext("Tanggal"); ?></td>
			<td><?php echo gettext("Tahun"); ?></td>
			<td><?php echo gettext("Jenis Keanggotaan"); ?></td>
		</tr>
		<?php

		//Get family roles
		$sSQL = "SELECT * FROM list_lst WHERE lst_ID = 2 ORDER BY lst_OptionSequence";
		$rsFamilyRoles = RunQuery($sSQL);
		$numFamilyRoles = mysql_num_rows($rsFamilyRoles);
		for($c=1; $c <= $numFamilyRoles; $c++)
		{
			$aRow = mysql_fetch_array($rsFamilyRoles);
			extract($aRow);
			$aFamilyRoleNames[$c] = $lst_OptionName;
			$aFamilyRoleIDs[$c] = $lst_OptionID;
		}

		for ($iCount = 1; $iCount <= $iFamilyMemberRows; $iCount++)
		{
		?>
		<tr>
			<td class="LabelColumn"><?php echo $iCount ?>:</td>
			<input type="hidden" name="PersonID<?php echo $iCount ?>" value="<?php echo $aPersonIDs[$iCount] ?>">
			<td class="TextColumn">
				<input name="FirstName<?php echo $iCount ?>" type="text" value="<?php echo $aFirstNames[$iCount] ?>" size="10">
				<div><font color="red"><?php echo $aFirstNameError[$iCount]; ?></font></div>
			</td>
			<td class="TextColumn">
				<input name="MiddleName<?php echo $iCount ?>" type="text" value="<?php echo $aMiddleNames[$iCount] ?>" size="10">
			</td>
			<td class="TextColumn">
				<input name="LastName<?php echo $iCount ?>" type="text" value="<?php echo $aLastNames[$iCount] ?>" size="10">
			</td>
			<td class="TextColumn">
				<select name="Gender<?php echo $iCount ?>">
					<option value="0" <?php if ($aGenders[$iCount] == 0) echo "selected" ?> ><?php echo gettext("Jenis Kelamin"); ?></option>
					<option value="1" <?php if ($aGenders[$iCount] == 1) echo "selected" ?> ><?php echo gettext("Pria"); ?></option>
					<option value="2" <?php if ($aGenders[$iCount] == 2) echo "selected" ?> ><?php echo gettext("Wanita"); ?></option>
				</select>
			</td>

			<td class="TextColumn">
				<select name="Role<?php echo $iCount ?>">
					<option value="0" <?php if ($aRoles[$iCount] == 0) echo "selected" ?> ><?php echo gettext("Hubungan Keluarga"); ?></option>
				<?php
				//Build the role select box
				for($c=1; $c <= $numFamilyRoles; $c++)
				{
					echo "<option value=\"" . $aFamilyRoleIDs[$c] . "\"";
					if ($aRoles[$iCount] == $aFamilyRoleIDs[$c]) echo " selected";
					echo ">" . $aFamilyRoleNames[$c] . "</option>";
				}
				?>
				</select>
			</td>
			<td class="TextColumn">
				<select name="BirthMonth<?php echo $iCount ?>">
					<option value="0" <?php if ($aBirthMonths[$iCount] == 0) { echo "selected"; } ?>><?php echo gettext("Kosong"); ?></option>
					<option value="01" <?php if ($aBirthMonths[$iCount] == 1) { echo "selected"; } ?>><?php echo gettext("January"); ?></option>
					<option value="02" <?php if ($aBirthMonths[$iCount] == 2) { echo "selected"; } ?>><?php echo gettext("February"); ?></option>
					<option value="03" <?php if ($aBirthMonths[$iCount] == 3) { echo "selected"; } ?>><?php echo gettext("March"); ?></option>
					<option value="04" <?php if ($aBirthMonths[$iCount] == 4) { echo "selected"; } ?>><?php echo gettext("April"); ?></option>
					<option value="05" <?php if ($aBirthMonths[$iCount] == 5) { echo "selected"; } ?>><?php echo gettext("May"); ?></option>
					<option value="06" <?php if ($aBirthMonths[$iCount] == 6) { echo "selected"; } ?>><?php echo gettext("June"); ?></option>
					<option value="07" <?php if ($aBirthMonths[$iCount] == 7) { echo "selected"; } ?>><?php echo gettext("July"); ?></option>
					<option value="08" <?php if ($aBirthMonths[$iCount] == 8) { echo "selected"; } ?>><?php echo gettext("August"); ?></option>
					<option value="09" <?php if ($aBirthMonths[$iCount] == 9) { echo "selected"; } ?>><?php echo gettext("September"); ?></option>
					<option value="10" <?php if ($aBirthMonths[$iCount] == 10) { echo "selected"; } ?>><?php echo gettext("October"); ?></option>
					<option value="11" <?php if ($aBirthMonths[$iCount] == 11) { echo "selected"; } ?>><?php echo gettext("November"); ?></option>
					<option value="12" <?php if ($aBirthMonths[$iCount] == 12) { echo "selected"; } ?>><?php echo gettext("December"); ?></option>
				</select>
			</td>
			<td class="TextColumn">
				<select name="BirthDay<?php echo $iCount ?>">
					<option value="0">Unk</option>
					<?php for ($x=1; $x < 32; $x++)
					{
						if ($x < 10) { $sDay = "0" . $x; } else { $sDay = $x; }
					?>
					<option value="<?php echo $sDay ?>" <?php if ($aBirthDays[$iCount] == $x) {echo "selected"; } ?>><?php echo $x ?></option>
				<?php } ?>
				</select>
			</td>
			<td class="TextColumn">
				<input name="BirthYear<?php echo $iCount ?>" type="text" value="<?php echo $aBirthYears[$iCount] ?>" size="4" maxlength="4">
				<div><font color="red"><?php echo $aBirthDateError[$iCount]; ?></font></div>
			</td>
			<td>
				<select name="Classification<?php echo $iCount ?>">
					<option value="0" <?php if ($aClassification[$iCount] == 0) echo "selected" ?>><?php echo gettext("Tidak Diisi"); ?></option>
					<option value="0">-----------------------</option>
					<?php
					//Get Classifications for the drop-down
					$sSQL = "SELECT * FROM list_lst WHERE lst_ID = 1 ORDER BY lst_OptionSequence";
					$rsClassifications = RunQuery($sSQL);

					//Display Classifications
					while ($aRow = mysql_fetch_array($rsClassifications))
					{
						extract($aRow);
						echo "<option value=\"" . $lst_OptionID . "\"";
						if ($aClassification[$iCount] == $lst_OptionID) echo " selected";
						echo ">" . $lst_OptionName . "&nbsp;";
					}
			echo "</select></td></tr>";
		}
		echo "</table></td></tr>";
	echo "<tr>";
	}

	echo "<td colspan=\"2\" align=\"center\">";
	echo "<input type=\"submit\" class=\"icButton\" value=\"" . gettext("Simpan") . "\" Name=\"FamilySubmit\">";
	if ($_SESSION['bAddRecords']) { echo "<input type=\"submit\" class=\"icButton\" value=\"Simpan dan Tambah\" name=\"FamilySubmitAndAdd\">"; }
	echo "<input type=\"button\" class=\"icButton\" value=\"" . gettext("Batal") . "\" Name=\"FamilyCancel\"";
	if (strlen($iFamilyID) > 0)
		echo "\"onclick=\"javascript:document.location='FamilyView.php?FamilyID=$iFamilyID';\">";
	else
		echo "\"onclick=\"javascript:document.location='SelectList.php';\">";
	echo "</td></tr></form></table>";
require "Include/Footer.php";
?>
